package com.unitedvision.core.domain;

import java.time.Month;
import java.util.Date;

public class Payment {
	private int id;
	private CompanyCustomer companyCustomer;
	private Operator operator;
	private Periode periode;
	private Date paymentDate;
	private long cost;
	
	public Payment() {
		super();
	}

	public Payment(CompanyCustomer companyCustomer, Operator operator, Periode periode, Date paymentDate, long cost) {
		super();
		this.companyCustomer = companyCustomer;
		this.operator = operator;
		this.periode = periode;
		this.paymentDate = paymentDate;
		this.cost = cost;
	}

	public Payment(Payer payer, Operator operator, Periode periode, Date paymentDate, long cost) {
		super();
		this.companyCustomer = (CompanyCustomer)payer.getPayableCustomer();
		this.operator = operator;
		this.periode = periode;
		this.paymentDate = paymentDate;
		this.cost = cost;
	}

	public Payment(int id, CompanyCustomer companyCustomer, Operator operator, Periode periode, Date paymentDate, long cost) {
		super();
		this.id = id;
		this.companyCustomer = companyCustomer;
		this.operator = operator;
		this.periode = periode;
		this.paymentDate = paymentDate;
		this.cost = cost;
	}

	public Payment(int id, Payer payer, Operator operator, Periode periode, Date paymentDate, long cost) {
		super();
		this.id = id;
		this.companyCustomer = (CompanyCustomer)payer.getPayableCustomer();
		this.operator = operator;
		this.periode = periode;
		this.paymentDate = paymentDate;
		this.cost = cost;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public CompanyCustomer getCompanyCustomer() {
		return companyCustomer;
	}

	public void setCompanyCustomer(CompanyCustomer companyCustomer) {
		this.companyCustomer = companyCustomer;
	}

	public Operator getOperator() {
		return operator;
	}

	public void setOperator(Operator operator) {
		this.operator = operator;
	}

	public Periode getPeriode() {
		return periode;
	}

	public void setPeriode(Periode periode) {
		this.periode = periode;
	}
	
	public int getYear() {
		if (periode == null)
			return 0;
		return periode.getYear();
	}
	
	public void setYear(int year) {
		if (periode == null)
			periode = new Periode();
		periode.setYear(year);
	}
	
	public Month getMonth() {
		if (periode == null)
			return Month.JANUARY;
		return periode.getMonth();
	}
	
	public void setMonth(Month month) {
		if (periode == null)
			periode = new Periode();
		periode.setMonth(month);
	}

	public Date getPaymentDate() {
		return paymentDate;
	}

	public void setPaymentDate(Date paymentDate) {
		this.paymentDate = paymentDate;
	}

	public long getCost() {
		return cost;
	}

	public void setCost(long cost) {
		this.cost = cost;
	}
	
	public Company getCompany() {
		return operator.getCompany();
	}

	@Override
	public String toString() {
		return "Payment [id=" + id + ", companyCustomer=" + companyCustomer
				+ ", operator=" + operator + ", periode=" + periode
				+ ", paymentDate=" + paymentDate + ", cost=" + cost + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((companyCustomer == null) ? 0 : companyCustomer.hashCode());
		result = prime * result + (int) (cost ^ (cost >>> 32));
		result = prime * result + id;
		result = prime * result
				+ ((operator == null) ? 0 : operator.hashCode());
		result = prime * result
				+ ((paymentDate == null) ? 0 : paymentDate.hashCode());
		result = prime * result + ((periode == null) ? 0 : periode.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Payment other = (Payment) obj;
		if (companyCustomer == null) {
			if (other.companyCustomer != null)
				return false;
		} else if (!companyCustomer.equals(other.companyCustomer))
			return false;
		if (cost != other.cost)
			return false;
		if (id != other.id)
			return false;
		if (operator == null) {
			if (other.operator != null)
				return false;
		} else if (!operator.equals(other.operator))
			return false;
		if (paymentDate == null) {
			if (other.paymentDate != null)
				return false;
		} else if (!paymentDate.equals(other.paymentDate))
			return false;
		if (periode == null) {
			if (other.periode != null)
				return false;
		} else if (!periode.equals(other.periode))
			return false;
		return true;
	}
}
